package com.yjhh.chdataservice.controller;

import com.yjhh.chdataservice.beans.*;
import com.yjhh.chdataservice.except.YJHHException;
import com.yjhh.chdataservice.service.IndustryInfoService;
import com.yjhh.chdataservice.util.CommonResultData;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "产业分布模块相关接口")
@RestController
@RequestMapping(value = "/service/fzjc/industry")
@Log4j2
public class IndustryInfoControler {

    @Autowired
    private IndustryInfoService industryInfoService;

    @ApiOperation(value = "获取市区脱贫岗位数据", notes = "获取市区脱贫岗位数据")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/outOfPovertyPost", method = RequestMethod.GET)
    public CommonResultData<List<TPGWPostInfoVo>> outOfPovertyPost(@RequestParam(name = "areaCode", defaultValue = "610000000000", required = false) String areaCode) {

        CommonResultData<List<TPGWPostInfoVo>> tPGWPostInfoVos = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            tPGWPostInfoVos = industryInfoService.outOfPovertyPost(areaCode);
            tPGWPostInfoVos.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("outOfPovertyPost", e);
            tPGWPostInfoVos = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return tPGWPostInfoVos;
    }

    @ApiOperation(value = "按区域统计产业分布信息", notes = "根据行政区划编码获取下级行政区划产业分布统计信息")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getIndustryInfoStaticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<IndustryInfoStaticsVo>> getIndustryInfoStaticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<IndustryInfoStaticsVo>> result = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间IndustryBaseInfoVo
            result = industryInfoService.getIndustryInfoStaticsByAreaCode(areaCode);
            result.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getIndustryInfoStaticsByAreaCode", e);
            result = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return result;
    }

    @ApiOperation(value = "根据行政区划编码获取产业信息列表", notes = "根据行政区划编码获取产业信息列表")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getIndustryInfoListByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<IndustryBaseInfoVo>> getIndustryInfoListByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<IndustryBaseInfoVo>> result = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            result = industryInfoService.getIndustryInfoListByAreaCode(areaCode);
            result.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("IndustryBaseInfoVo", e);
            result = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return result;
    }

    @ApiOperation(value = "获取产业详细信息", notes = "获取产业详细信息")
    @ApiImplicitParam(name = "industryId", value = "产业ID", required = true, paramType = "query", dataType = "String", defaultValue = "0f8c3e05-0f53-4509-8ffa-0580733e13b8")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getIndustryInfo", method = RequestMethod.GET)
    public CommonResultData<IndustryInfoVo> getIndustryInfo(@RequestParam String industryId) {
        CommonResultData<IndustryInfoVo> result = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            result = industryInfoService.getIndustryInfo(industryId);
            result.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getIndustryInfo", e);
            result = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return result;
    }

    @ApiOperation(value = "获取脱贫产业平均薪资统计", notes = "根据行政区划编码获取脱贫产业平均薪资统计")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getAvgMonthMoneyByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<CommonNameValueVo<Long>>> getAvgMonthMoneyByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<CommonNameValueVo<Long>>> result = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            result = industryInfoService.getAvgMonthMoneyByAreaCode(areaCode);
            result.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getAvgMonthMoneyByAreaCode", e);
            result = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return result;
    }

    @ApiOperation(value = "获取产业产业分布统计", notes = "根据行政区划编码获取产业产业分布统计")
    @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue = "610000000000")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getIndustryStaticsByAreaCode", method = RequestMethod.GET)
    public CommonResultData<List<CommonNameValueVo<Long>>> getIndustryStaticsByAreaCode(@RequestParam String areaCode) {
        CommonResultData<List<CommonNameValueVo<Long>>> result = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            result = industryInfoService.getIndustryStaticsByAreaCode(areaCode);
            result.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getIndustryStaticsByAreaCode", e);
            result = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return result;
    }

}
